import { API_LIST } from '../../../Api/Api'
import { commonTableList } from '../Common/common'
import { AddDataButton, DelDataButton, AnnexButton } from '../Common/options'

export const InspectionDetailAttachment = async ({ twoData, actionRef, Permission, OptionsEvent, type }) => {
    const mapping = {
        quality: {
            get: API_LIST()['getQualityDetailAttachment'],
            added: 'posQualityDetailAttachment',
            del: 'QualityDetailAttachmentNew',
            initUuid: 'qualityDetailUuid',
        },
        security: {
            get: API_LIST()['getSecurityDetailAttachment'],
            added: 'posSecurityByUuid',
            del: 'SecurityDetailAttachmentNew',
            initUuid: 'securityDetailUuid',
        },
    }

    const { get, added, del, initUuid } = mapping[type]

    let dataList = {
        type: '整改附件列表',
        width: 800,
        classification: 'SelectModal',
        hideInSelect: true,
        hideInSearch: true,
        pageSize: 10,
        params: { pageIndex: 1, [initUuid]: twoData.uuid },
        initialValues: { [initUuid]: twoData.uuid },
        get,
        added,
        options: [
            twoData.handling === 1 && (
                <AddDataButton OptionsEvent={OptionsEvent} type="primary" icon="add" title="添加附件" />
            ),
        ],
        columns: [
            commonTableList.uuid,
            {
                dataIndex: initUuid,
                title: initUuid,
                valueType: 'hidden',
                hideInTable: true,
            },
            {
                dataIndex: 'originalName',
                title: '附件名称',
                valueType: 'input',
                rules: true,
                ellipsis: true,
                width: 240,
                hideInSearch: true,
                hideInModify: true,
                hideInAdded: true,
            },
            {
                dataIndex: 'attachmentUuid',
                title: '文件附件',
                valueType: 'upload',
                valueFile: [1],
                fileUrl: 'fileUrl',
                rules: true,
                hideInTable: true,
            },
            {
                dataIndex: 'fileUrl',
                title: '文件附件',
                valueType: 'hidden',
                hideInSearch: true,
                hideInTable: true,
                hideInAdded: true,
                hideInModify: true,
                width: 240,
            },
            {
                dataIndex: 'keyword',
                title: '整改类型',
                valueType: 'select',
                valueEnum: { 1: '整改过程', 2: '整改结果' },
                width: 160,
                rules: true,
            },
            {
                dataIndex: 'remark',
                title: '整改描述',
                valueType: 'textarea',
                width: 240,
            },
            {
                title: '操作',
                valueType: 'systemOperation',
                fixed: 'right',
                width: 300,
                hideInSearch: true,
                hideInAdded: true,
                hideInModify: true,
                render: (_, record) => {
                    const { fileUrl, uuid } = record
                    return [
                        fileUrl && <AnnexButton OptionsEvent={OptionsEvent} key="see" url={fileUrl} title="查看附件" />,
                        twoData.handling === 1 && (
                            <DelDataButton
                                OptionsEvent={OptionsEvent}
                                key="del"
                                title="删除"
                                url={del}
                                uuid={[twoData.uuid, uuid]}
                            />
                        ),
                    ]
                },
            },
        ],
    }
    return dataList
}
